package com.gok.pay.base;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Created by alvawen on 2017/7/28 0028.
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class RestResult {

    public static final String CODE_SUCCESS = "0";
    public static final String CODE_DEFAULT_FAILURE = "-1";
    public static final RestResult SUCCESS = new RestResult(CODE_SUCCESS, "ok");

    public static RestResult failureDefault(String msg) {
        return new RestResult(CODE_DEFAULT_FAILURE, msg);
    }

    public static String successString(String s) {
        return String.format("{'code':'0','msg':'ok',%s}", s);
    }

    public static RestResult successValue(Object s) {
        return RestResult.successObject(s);
    }

    public static RestResult success(String message) {
        SuccessObject sv = new SuccessObject();
        sv.setCode(SUCCESS.code);
        sv.setMsg(message);
        return sv;
    }

    public static RestResult successObject(Object value) {
        SuccessObject sv = new SuccessObject(value);
        sv.setCode(SUCCESS.code);
        sv.setMsg(SUCCESS.msg);
        return sv;
    }

    private String code;
    private String msg;
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
class SuccessObject extends RestResult {
    private Object result;
}

